package yl.codecraft.dsa.sort;

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;

import java.util.Arrays;
import java.util.Random;

public class BubbleSort extends BaseSort{
	public static void main(String[] args) {
		int[] a = generateRandomArray(20);
		long s = System.nanoTime();
		int[] b= sort(a);
		long dur = System.nanoTime() - s;		
		System.out.println(Arrays.toString(b));
		System.out.println(dur);	
	}
	public static int[] sort(int[] a){
        for( int i=0;i<a. length-1;i++){  //n个数排序，只用进行n-1趟
            //对当前无序区间score[0......length-i-1]进行排序(j的范围很关键，这个范围是在逐步缩小的)
            for( int j=0;j<a. length-i-1;j++){
                if(a[j] < a[j + 1]){
                    int tmp = a[j];
                    a[j] = a[j+1];
                    a[j+1] = tmp;
                }
            }
        }
        return a;
	}
}
